package com.showcai.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.showcai.dao.GamePetWikiMapper;
import com.showcai.module.BaseModule;
import com.showcai.module.GamePetWiki;
import com.showcai.myRunTime.MyRunTimeExcption;
import com.showcai.service.GamePetWikiService;
import com.showcai.service.OrderService;
import com.showcai.service.ServiceBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Baggio on 2018-11-5.
 */
@Service
public class GamePetWikiServiceImpl extends ServiceBase implements GamePetWikiService {
    @Autowired
    GamePetWikiMapper gamePetWikiMapper;



    private void  insert(GamePetWiki gamePetWiki){
        gamePetWikiMapper.insertGamePetWiki(gamePetWiki);
    }
    private void  update(GamePetWiki gamePetWiki){
        gamePetWikiMapper.updateGamePetWikiByPrimaryKeySelective(gamePetWiki);
    }

    @Override
    public void modifyGamePetWiki(GamePetWiki gamePetWiki) throws MyRunTimeExcption {
        GamePetWiki gamePetWiki1 = gamePetWikiMapper.getGamePetWikiById(gamePetWiki.getTid());
        if(gamePetWiki1==null){
            gamePetWiki.setCreateTime(new Date());
            this.insert(gamePetWiki);
            return;
        }
        this.update(gamePetWiki);
    }

    @Override
    public PageInfo getGamePetWikiList(Map<String, String> map) throws MyRunTimeExcption {

        PageHelper.startPage(Integer.parseInt(map.get("page")),Integer.parseInt(map.get("pageSize")));
        List<GamePetWiki> list = gamePetWikiMapper.getGamePetWikiList();
        PageInfo pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public GamePetWiki getGamePetWikiById(Long id) throws MyRunTimeExcption {
        return gamePetWikiMapper.getGamePetWikiById(id);
    }

    @Override
    public GamePetWiki getGamePetWikiByRandom() throws MyRunTimeExcption {
        return null;
    }
}
